package com.yun.algorithmproblem.leetcode;

import java.util.HashMap;
import java.util.Map;

public class Leetcode3 {

    public int lengthOfLongestSubstring(String s) {
        Map<Character,Integer> m=new HashMap<>();
        int max=0;
        for (int end = 0,start=0; end < s.length(); end++) {
            char c=s.charAt(end);
            if(m.containsKey(c)){
                start=Math.max(m.get(c),start);
            }
            max=Math.max(max,end-start+1);
            m.put(c,end+1);
        }
        return max;
    }

    public static void main(String[] args) {
        String s="pwwkew";
        int res=new Leetcode3().lengthOfLongestSubstring(s);
        System.out.println(res);
    }
}
